package edu.cuit.avatar;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/9 13:48
 */
public class StringBuilderTest {
    public static void main(String[] args) {
        if(args.length == 0)
            return;
        var tableName = "emp";
        var sb = new StringBuilder();
        //向缓冲区追加内容
        sb.append("insert into").append(' ').append(tableName).append('(');

        for(var field : args)
            sb.append(field).append(',');

        //删除最后多余的,
        sb.deleteCharAt(sb.length() - 1);

        sb.insert(sb.length(), ") values(");
        for(var field : args)
            sb.append('?').append(',');

        //将最后字符,替换为)
        sb.setCharAt(sb.length() - 1, ')');

        //将StringBuilder转为字符串
        String sql = sb.toString();
        System.out.println(sql);
    }
}
